

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class EmployeeEntryForm extends JFrame {
    private JTextField nameField;
    private JComboBox<String> designationComboBox;
    private JTextField dobField;

    public EmployeeEntryForm() {
        setTitle("Employee Entry");
        setSize(600, 300);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        JPanel panel = new JPanel();
        panel.setLayout(new GridBagLayout());
        GridBagConstraints gbc = new GridBagConstraints();
        gbc.insets = new Insets(5, 5, 5, 5);

        JLabel entryLabel = new JLabel("Employee Entry");
        entryLabel.setFont(new Font("Arial", Font.BOLD, 20));
        entryLabel.setHorizontalAlignment(JLabel.CENTER);
        entryLabel.setVerticalAlignment(JLabel.CENTER);
        gbc.gridx = 0;
        gbc.gridy = 0;
        gbc.gridwidth = 2;
        panel.add(entryLabel, gbc);

        JLabel nameLabel = new JLabel("Name:");
        nameField = new JTextField(20);
        gbc.gridx = 0;
        gbc.gridy = 1;
        gbc.gridwidth = 1;
        panel.add(nameLabel, gbc);
        gbc.gridx = 1;
        panel.add(nameField, gbc);

        JLabel designationLabel = new JLabel("Designation:");
        String[] designations = {"Manager", "Engineer", "Designer", "Accountant"};
        designationComboBox = new JComboBox<>(designations);
        gbc.gridx = 0;
        gbc.gridy = 2;
        panel.add(designationLabel, gbc);
        gbc.gridx = 1;
        panel.add(designationComboBox, gbc);

        JLabel dobLabel = new JLabel("Date of Birth (yyyy-MM-dd):");
        dobField = new JTextField(10);
        gbc.gridx = 0;
        gbc.gridy = 3;
        panel.add(dobLabel, gbc);
        gbc.gridx = 1;
        panel.add(dobField, gbc);

        JButton submitButton = new JButton("Submit");
        submitButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                String name = nameField.getText();
                String designation = (String) designationComboBox.getSelectedItem();
                String dobText = dobField.getText();

                SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
                Date dob = null;
                try {
                    dob = dateFormat.parse(dobText);
                } catch (ParseException ex) {
                    JOptionPane.showMessageDialog(null, "Invalid Date of Birth format (yyyy-MM-dd).");
                    return;
                }
                // You can process the input data here
                String message = "Name: " + name + "\nDesignation: " + designation + "\nDate of Birth: " + dateFormat.format(dob);
                JOptionPane.showMessageDialog(null, message);
            }
        });
        gbc.gridx = 0;
        gbc.gridy = 4;
        gbc.gridwidth = 2;
        gbc.anchor = GridBagConstraints.CENTER;
        panel.add(submitButton, gbc);

        add(panel);
        setVisible(true);
    }

}
